package com.itheima.mapper;

import com.itheima.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TaoBaoMapper {
    @Options()
    @Insert("insert into lkd_shopping.tb_sku (sku_name,sku_image,price,class_id,is_discount,unit,brand_name) values " +
            "(#{skuName},#{skuImage},#{price},#{classId},#{isDiscount},#{unit},#{brandName}) ")
    void add(Product product);


    @Select("select * from lkd_shopping.tb_sku where sku_id=#{skuId}")
    Product getById(Long skuId);

    @Select("select * from lkd_shopping.tb_sku where sku_name like concat('%',IFNULL(#{skuName},''),'%') " +
            "and price between #{priceDown} and #{priceUp} and class_id=IFNULL(#{classId},'%') and brand_name=IFNULL(#{brandName},'%')")
    List<Product> list(String skuName, String priceUp, String priceDown, String classId, String brandName);


    @Delete("delete from lkd_shopping.tb_sku where sku_id=#{skuId}")
    void deleteById(Long skuId);

    @Update("update lkd_shopping.tb_sku set sku_id=#{skuId},sku_name=#{skuName},sku_image=#{skuImage}," +
            "price=#{price},class_id=#{classId},is_discount=#{isDiscount},unit=#{unit},brand_name=#{brandName}")
    void update(Product product);
}
